<?php
	/*
		UserCake Version: 1.4
		http://usercake.com
		
		Developed by: Adam Davis
	*/
	require_once("models/config.php");
	require_once("ui.php");
	require_once("stats/db.php");
	
	//Prevent the user visiting the logged in page if he/she is not logged in
	if(!isUserLoggedIn()) { header("Location: login.php"); die(); }
	
	$GETReportId = $_GET['reportId'];
	$GETReportId = htmlspecialchars($GETReportId);
	
	$dbReportAnswer = loadReportStats($GETReportId);
	
	$errors = array();
	$report = $dbReportAnswer['report'];
	
	if ($dbReportAnswer['error']) {
		$errors[] = $dbReportAnswer['error'];
	} else {
		// report ID is fine, check access rights
		global $loggedInUser;
		$isAdmin = $loggedInUser->isAdministrator();
		if (!$isAdmin) {
			if ($report->userId != $loggedInUser->user_id) {
				$errors[] = "Unauthorized access";
			} 
		}
		
	}
?>
<?php printPageHead(null, null); ?>

	<?php printNavigationBar('index', '') ?>		

	<?php 
		if (count($errors) != 0) {
			foreach ($errors as $i => $error) {
				echo "$error<br>";
			} 
		} else {
	?>

	<div id="content" class="container_16 clearfix">
		<?php 
			printReportDetails($report);
		?>
	</div>
	
	<?php 
		}
	?>
<?php printPageFoot(); ?>

